﻿<template>
  <a-modal
    :title="title"
    width="40%"
    :visible="visible"
    :confirmLoading="loading"
    @ok="handleSubmit"
    @cancel="()=>{this.visible=false}"
  >
    <a-spin :spinning="loading">
      <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
        <a-form-model-item label="备注" prop="Remark">
          <a-input v-model="entity.Remark" autocomplete="off" placeholder="备注" />
        </a-form-model-item>
        <a-form-model-item label="价格表明细ID" prop="DIdPriceList">
          <a-input v-model="entity.DIdPriceList" autocomplete="off" placeholder="价格表明细ID" />
        </a-form-model-item>
        <a-form-model-item label="数量上限" prop="NumTopLimit">
          <a-input v-model="entity.NumTopLimit" autocomplete="off" placeholder="数量上限" />
        </a-form-model-item>
        <a-form-model-item label="数量下限" prop="NumLowerLimit">
          <a-input v-model="entity.NumLowerLimit" autocomplete="off" placeholder="数量下限" />
        </a-form-model-item>
        <a-form-model-item label="含税价格" prop="Tax_Included_Price">
          <a-input v-model="entity.Tax_Included_Price" autocomplete="off" placeholder="含税价格" />
        </a-form-model-item>
        <a-form-model-item label="不含税价格" prop="Tax_Excluded_Price">
          <a-input v-model="entity.Tax_Excluded_Price" autocomplete="off" placeholder="不含税价格" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
export default {
  props: {
    parentObj: Object
  },
  data () {
    return {
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,
      loading: false,
      entity: {},
      rules: {},
      title: ''
    }
  },
  methods: {
    init () {
      this.visible = true
      this.entity = {}
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    openForm (id, title) {
      this.init()
      this.title = title
      if (id) {
        this.loading = true
        this.$http.post('/QuotationManagement/Quot_PriceListLadder/GetTheData', { id: id }).then(resJson => {
          this.loading = false

          this.entity = resJson.Data
        })
      }
    },
    handleSubmit () {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.loading = true
        this.$http.post('/QuotationManagement/Quot_PriceListLadder/SaveData', this.entity).then(resJson => {
          this.loading = false

          if (resJson.Success) {
            this.$message.success('操作成功!')
            this.visible = false

            this.parentObj.getDataList()
          } else {
            this.$message.error(resJson.Msg)
          }
        })
      })
    }
  }
}
</script>
